import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';


class CartNum extends StatefulWidget {
  final Map<String,dynamic> selectProductValue;
  CartNum({this.selectProductValue});

  _CartNumState createState() => _CartNumState();
}

class _CartNumState extends State<CartNum> {
  Map<String,dynamic> selectProductValue;
  int _count=1;
  @override
  void initState() {
    super.initState();
    this.selectProductValue=widget.selectProductValue;
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      width: 168.w,
      decoration:
          BoxDecoration(border: Border.all(width: 2.w, color: Colors.black12)),
      child: Row(
        children: <Widget>[
          _leftBtn(),
          _centerArea(),
          _rightBtn()
        ],
      ),
    );
  }

  //左侧按钮

  Widget _leftBtn() {
    return InkWell(
      onTap: () {
        if( _count>1){
          setState(() {
            _count--;
            selectProductValue['count']=_count;
          });
        }
      },
      child: Container(
        alignment: Alignment.center,
        width: 45.w,
        height: 45.h,
        child: Text("-"),
      ),
    );
  }

  //右侧按钮
  Widget _rightBtn() {
    return InkWell(
      onTap: (){
          setState(() {
            _count++;
            selectProductValue['count']=_count;
          });
      },
      child: Container(
        alignment: Alignment.center,
        width: 45.w,
        height: 45.h,
        child: Text("+"),
      ),
    );
  }

//中间
  Widget _centerArea() {
    return Container(
      alignment: Alignment.center,
      width: 70.w,
      decoration: BoxDecoration(
          border: Border(
        left: BorderSide(width: 2.w, color: Colors.black12),
        right: BorderSide(width: 2.w, color: Colors.black12),
      )),
      height: 45.h,
      child: Text("${this._count}"),
    );
  }
}
